package com.bharatonjava.hospital.service.patient;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.bharatonjava.hospital.dao.patient.IPatientDao;
import com.bharatonjava.hospital.domain.Address;
import com.bharatonjava.hospital.domain.Patient;
import com.bharatonjava.hospital.dto.PatientProfileDto;

public class PatientService implements IPatientService {

	private final Logger log = Logger.getLogger(PatientService.class);

	private IPatientDao patientDao;
	
	@Autowired
	public void setPatientDao(IPatientDao patientDao) {
		this.patientDao = patientDao;
	}
	
	@Override
	public int createPatient(Patient patient, Address address) {

		log.info("PatientService - createPatient");
		
		int status = patientDao.createPatient(patient, address);
		return status;
	}

	@Override
	@Transactional
	public PatientProfileDto getPatientProfile(Long patientId) {
		PatientProfileDto dto = new PatientProfileDto();
		Patient patient = patientDao.getPatientById(patientId);
		Address address = patientDao.getPatientAddress(patientId);
		dto.setPatient(patient);
		dto.setAddress(address);
		
		return dto;
	}

}
